# Contributor: Pedro Filipe <xpecex@outlook.com>
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Martell Malone <martell@marinelayer.io>
# Contributor: Craig Andrews <candrews@integralblue.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=wine
pkgver=7.12
pkgrel=0
pkgdesc="A compatibility layer for running Windows programs"
url="https://www.winehq.org"
arch="x86 x86_64"
license="LGPL-2.0-or-later"
options="textrels !check" # As of 2.0.3 most of the tests fails
subpackages="$pkgname-dev $pkgname-doc"
depends_dev="$pkgname perl"
makedepends="
	alsa-lib-dev
	autoconf
	automake
	bison
	cups-dev
	dbus-dev
	flex-dev
	fontconfig-dev
	freetype-dev
	gnutls-dev
	gstreamer-dev
	gst-plugins-base-dev
	krb5-dev
	libgphoto2-dev
	libpcap-dev
	libusb-dev
	libxcomposite-dev
	libxcursor-dev
	libxdamage-dev
	libxi-dev
	libxinerama-dev
	libxrandr-dev
	libxrender-dev
	mesa-dev
	mingw-w64-gcc
	mpg123-dev
	ncurses-dev
	openal-soft-dev
	opencl-dev
	sane-dev
	sdl2-dev
	udisks2-dev
	v4l-utils-dev
	vkd3d-dev
	vulkan-loader-dev
	"
checkdepends="xvfb-run"
source="https://dl.winehq.org/wine/source/7.x/wine-$pkgver.tar.xz
	rpath.patch
	"

prepare() {
	default_prepare
	# fix opencl header detection
	sed 's|OpenCL/opencl.h|CL/opencl.h|g' -i configure*
}

build() {
	local _win64 _no_pie
	case "$CARCH" in
		x86_64) _win64=--enable-win64;;
		x86) _no_pie="-no-pie";;
	esac
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libdir=/usr/lib \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--with-dbus \
		--without-ldap \
		--with-mingw \
		--with-x \
		--with-vulkan \
		$_win64
	make LDFLAGS="$LDFLAGS $_no_pie" \
		tools/widl/widl \
		tools/winebuild/winebuild \
		tools/widl/widl \
		tools/winebuild/winebuild \
		tools/winegcc/winegcc \
		tools/wrc/wrc
	make -j6
}

check() {
	xvfb-run make test
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 tools/wineapploader \
		"$pkgdir"/usr/bin/wineapploader

	local file
	for file in msiexec notepad regedit regsvr32 wineboot \
		winecfg wineconsole winefile winemine winepath
	do
		rm "$pkgdir"/usr/bin/$file
		ln -sf /usr/bin/wineapploader "$pkgdir"/usr/bin/$file
	done
}

dev() {
	default_dev

	install -d "$subpkgdir"/usr/bin

	local file
	for file in widl wmc wrc winebuild winedump function_grep.pl \
		 winedbg winemaker winegcc winecpp wineg++
	do
		mv "$pkgdir"/usr/bin/$file "$subpkgdir"/usr/bin/
	done
}

doc() {
	default_doc
	rm -fr "$subpkgdir"/usr/share/man/*.UTF-8
}

sha512sums="
4746fb1c3d0ec7f20e22d821f8e88e5415b85cb60f53e9ad61b89e8321b6a6b2999eb2b70c7ac46477f633bccb6c2aba49ce2655c380cb85cd5c71dbe4af50b4  wine-7.12.tar.xz
d42a367d30b93fe36b8d6418d53f3c931debef2e9b77bc73e22fff04f5f0d7b9e6622beb78592c814beb32ca214fb7e9c019c652fb2612c61358ba162a520b9d  rpath.patch
"
